/*
 *http://www.apache.org/licenses/LICENSE-2.0
 * Copyright (c) 2021 fullset
 * @Description: 颜色转换类
 * @author: pangps
 * @date: 2021/5/29 11:25
 */
package com.fs.core.util;

public class ColorUtil {

	/**
	 * grb转int
	 * @param r
	 * @param g
	 * @param b
	 * @return
	 */
	public static int rgbToInt(int r, int g, int b) {
		return r + g * 256 + b * 256 * 256;
	}

	/**
	 * 把 rgb(2,2,2) 格式的转换为数字
	 * @param rgbStr
	 * @return
	 */
	public static int rgbStrToInt(String rgbStr) {
		int r, g,b;
		try {
			String tempStr=rgbStr.substring(rgbStr.indexOf("(")+1,rgbStr.indexOf(")"));
			String[] tempArr=tempStr.split(",");
			r = Integer.parseInt(tempArr[0].trim());
			g = Integer.parseInt(tempArr[1].trim());
			b = Integer.parseInt(tempArr[2].trim());
		} catch (Exception e) {
			return 0;
		}

		return r + g * 256 + b * 256 * 256;
	}

	/**
	 * int转rgb
	 * @param color
	 * @return
	 */
    public static String intToRGB(int color){
        int b = color / (256 * 256);
        int g = (color - b * 256 * 256) / 256;
        int r = color - b * 256 * 256 - g * 256;
        return "GRB("+r+","+g+","+b+")";
    }

	public static void main(String[] args) {
    	System.out.println(1 == 0 );
	}
}
